﻿using System;
using DG.Tweening;
using UnityEngine;

namespace JQMergeFramework
{
    public class HammerAnim: MonoBehaviour
    {
        
        //锤子
        public Transform hammerTrans;
        //特效
        public ParticleSystem effect;
        
        public void PlayAnim(Action call)
        {
            DOTween.Kill(this.GetInstanceID());
            
            this.transform.localPosition = Vector3.zero;
            this.transform.localEulerAngles = Vector3.zero;
            this.hammerTrans.localEulerAngles = new Vector3(0, 90, 0);
            hammerTrans.gameObject.SetActive(true);
            // hammerTrans.localEulerAngles = Vector3.zero;
            Sequence sq =  DOTween.Sequence().SetId(this.GetInstanceID());
            sq.Append(hammerTrans.DOLocalRotate(new Vector3(-45, 90, 0), 0.3F).SetEase(Ease.Linear));
            sq.AppendCallback(() =>
            {
                effect.Play();
                hammerTrans.gameObject.SetActive(false);
                call?.Invoke();
                
        
            });
            sq.Append(hammerTrans.DOLocalRotate(new Vector3(-90, 90, 0), 0.3F).SetEase(Ease.OutBack));
            sq.AppendInterval(0.5f);
            sq.OnComplete(() =>
            {
                EffectPool.I.PutPoolObject(PoolName.Hammer,this.gameObject);
            });
            sq.Play();
        }
        
    }
}